package o2o.delivery.model.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.jinyou.utils.common.DateUtils;
import o2o.dao.PO.order.ORDER_STATUS;
import o2o.dao.PO.order.OrderInfo;

import java.util.Date;

/**
 * @author Jahnke【1029777564@qq.com】
 * @ClassName DeliveryOrderVO
 * @Description:
 * @date 2021/1/28 15:47
 * @Version 1.0
 */
public class DeliveryOrderVO {

    private String originOrderNo;
    private String plateOrderNo;
    private String orderNo;
    private String source;
    private String state;
    private Double distance;
    private Double deliverMoney;
    private String deliveryUser;
    private String deliveryUserPhone;
    private Double deliveryUserLat;
    private Double deliveryUserLng;
    private String orderCreateTime;
    private String orderAcceptTime;
    private String orderFetchTime;
    private String orderFinishTime;
    private String orderCancelTime;
    private String cancelReason;
    private String errorReason;

    @JSONField(serialize = false)
    private String callBack;

    public static DeliveryOrderVO convertFromInfo(String source, String originOrderNo, OrderInfo orderInfo) {
        DeliveryOrderVO vo = new DeliveryOrderVO();
        vo.setSource(source).setOriginOrderNo(originOrderNo).setDistance(orderInfo.getDistance()).setDeliverMoney(orderInfo.getDeliveryPrice());
        vo.setDeliveryUser(orderInfo.getPostmanName()).setDeliveryUserPhone(orderInfo.getPostmanPhone());
        vo.setOrderCreateTime(DateUtils.sdfDateTime.get().format(new Date(orderInfo.getCreateTime())));
        if (orderInfo.getShopSureTime() == null || orderInfo.getShopSureTime() == 0) {
            vo.setOrderAcceptTime(DateUtils.sdfDateTime.get().format(new Date(orderInfo.getCreateTime())));
        } else {
            vo.setOrderAcceptTime(DateUtils.sdfDateTime.get().format(new Date(orderInfo.getShopSureTime())));
        }
        vo.setOrderFetchTime(orderInfo.getPostmanPullTime() != null && orderInfo.getPostmanPullTime() > 0 ? DateUtils.sdfDateTime.get().format(new Date(orderInfo.getPostmanPullTime())) : null);
        vo.setOrderFinishTime(orderInfo.getPostmanFinishTime() != null && orderInfo.getPostmanFinishTime() > 0 ? DateUtils.sdfDateTime.get().format(new Date(orderInfo.getPostmanFinishTime())) : null);
        // if (orderInfo.getOrderStatus() == ORDER_STATUS.CANCEL) {
        //     vo.setOrderCancelTime(orderInfo.getPostmanFinishTime() != null && orderInfo.getPostmanFinishTime() > 0 ? DateUtils.sdfDateTime.get().format(new Date(orderInfo.getPostmanFinishTime())) : null);
        // }
        vo.setCancelReason(orderInfo.getCancelReason());
        vo.setErrorReason(orderInfo.getPostFailReason());
        vo.setState(getOderState(orderInfo.getOrderStatus()));
        vo.setCallBack(orderInfo.getDeliveryCallBack()).setPlateOrderNo(orderInfo.getDeliveryPlateOrderNo());

        return vo;
    }

    // 解析订单状态
    public static String getOderState(Integer orderState) {
        if (orderState == ORDER_STATUS.OVER || orderState == ORDER_STATUS.POSTMAN_FINISH) {
            return "done";
        } else if (orderState == ORDER_STATUS.SHOP_SURE || orderState == ORDER_STATUS.PAYED) {
            return "wait_accept";
        } else if (orderState == ORDER_STATUS.POSTMAN_SURE) {
            return "wait_fetch";
        } else if (orderState == ORDER_STATUS.POSTMAN_DAODIAN) {
            return "arrive_shop";
        } else if (orderState == ORDER_STATUS.PEISONG || orderState == ORDER_STATUS.POSTMAN_PULL_GOODS) {
            return "delivering";
        } else if (orderState == ORDER_STATUS.CANCEL || orderState == ORDER_STATUS.CANCEL_BY_SYSTEM || orderState == ORDER_STATUS.PAYED_CANCEL) {
            return "cancel";
        }

        return "";
    }

    public String getOriginOrderNo() {
        return originOrderNo;
    }

    public DeliveryOrderVO setOriginOrderNo(String originOrderNo) {
        this.originOrderNo = originOrderNo;
        return this;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public DeliveryOrderVO setOrderNo(String orderNo) {
        this.orderNo = orderNo;
        return this;
    }

    public String getSource() {
        return source;
    }

    public DeliveryOrderVO setSource(String source) {
        this.source = source;
        return this;
    }

    public String getState() {
        return state;
    }

    public DeliveryOrderVO setState(String state) {
        this.state = state;
        return this;
    }

    public Double getDistance() {
        return distance;
    }

    public DeliveryOrderVO setDistance(Double distance) {
        this.distance = distance;
        return this;
    }

    public Double getDeliverMoney() {
        return deliverMoney;
    }

    public DeliveryOrderVO setDeliverMoney(Double deliverMoney) {
        this.deliverMoney = deliverMoney;
        return this;
    }

    public String getDeliveryUser() {
        return deliveryUser;
    }

    public DeliveryOrderVO setDeliveryUser(String deliveryUser) {
        this.deliveryUser = deliveryUser;
        return this;
    }

    public String getCallBack() {
        return callBack;
    }

    public DeliveryOrderVO setCallBack(String callBack) {
        this.callBack = callBack;
        return this;
    }

    public String getDeliveryUserPhone() {
        return deliveryUserPhone;
    }

    public DeliveryOrderVO setDeliveryUserPhone(String deliveryUserPhone) {
        this.deliveryUserPhone = deliveryUserPhone;
        return this;
    }

    public Double getDeliveryUserLat() {
        return deliveryUserLat;
    }

    public DeliveryOrderVO setDeliveryUserLat(Double deliveryUserLat) {
        this.deliveryUserLat = deliveryUserLat;
        return this;
    }

    public Double getDeliveryUserLng() {
        return deliveryUserLng;
    }

    public DeliveryOrderVO setDeliveryUserLng(Double deliveryUserLng) {
        this.deliveryUserLng = deliveryUserLng;
        return this;
    }

    public String getOrderCreateTime() {
        return orderCreateTime;
    }

    public DeliveryOrderVO setOrderCreateTime(String orderCreateTime) {
        this.orderCreateTime = orderCreateTime;
        return this;
    }

    public String getOrderAcceptTime() {
        return orderAcceptTime;
    }

    public DeliveryOrderVO setOrderAcceptTime(String orderAcceptTime) {
        this.orderAcceptTime = orderAcceptTime;
        return this;
    }

    public String getOrderFetchTime() {
        return orderFetchTime;
    }

    public DeliveryOrderVO setOrderFetchTime(String orderFetchTime) {
        this.orderFetchTime = orderFetchTime;
        return this;
    }

    public String getOrderFinishTime() {
        return orderFinishTime;
    }

    public DeliveryOrderVO setOrderFinishTime(String orderFinishTime) {
        this.orderFinishTime = orderFinishTime;
        return this;
    }

    public String getOrderCancelTime() {
        return orderCancelTime;
    }

    public DeliveryOrderVO setOrderCancelTime(String orderCancelTime) {
        this.orderCancelTime = orderCancelTime;
        return this;
    }

    public String getCancelReason() {
        return cancelReason;
    }

    public DeliveryOrderVO setCancelReason(String cancelReason) {
        this.cancelReason = cancelReason;
        return this;
    }

    public String getErrorReason() {
        return errorReason;
    }

    public DeliveryOrderVO setErrorReason(String errorReason) {
        this.errorReason = errorReason;
        return this;
    }

    public String getPlateOrderNo() {
        return plateOrderNo;
    }

    public DeliveryOrderVO setPlateOrderNo(String plateOrderNo) {
        this.plateOrderNo = plateOrderNo;
        return this;
    }
}
